//
//  FourViewController.m
//  5-24
//
//  Created by 王成龙 on 16/6/1.
//  Copyright © 2016年 wcl. All rights reserved.
//

#import "FourViewController.h"

@interface FourViewController ()

@end

@implementation FourViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    self.navigationItem.title= @"功能";
    self.view.backgroundColor=[UIColor whiteColor];
    UIButton * abc = [UIButton buttonWithType:UIButtonTypeSystem];
    [abc setTitle:@"王成龙" forState:UIControlStateNormal];
    [abc setImage:[UIImage imageNamed:@"5"] forState:UIControlStateNormal];//按钮旁边的图片
    [abc setTitle:@"帅哥" forState:UIControlStateHighlighted];
    [abc setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    abc.layer.borderWidth = 1;//
    abc.layer.cornerRadius = 6;
    abc.layer.borderColor = [UIColor blueColor].CGColor;//按钮名字的颜色
    abc.frame = CGRectMake(0,0, 100,44);//0,0 在下面定义了   后面那个是长度和高度
    abc.center = CGPointMake(self.view.frame.size.width/2,100 );//按钮在屏幕的位置
    
    [abc addTarget:self action:@selector(onCick:) forControlEvents:UIControlEventTouchUpInside];
    [abc addTarget:self action:@selector(onCick2:) forControlEvents:UIControlEventTouchDown];
    [self.view addSubview:abc];//把它粘贴到 self.view
              //输出汉字//
    UILabel *l = [[UILabel alloc] initWithFrame:CGRectMake(120, 250, 200, 44)];
    l.text = @"大冒险";
    l.tag = 100;
    l.textAlignment = NSTextAlignmentCenter;//文字在边框居中
    [self.view addSubview:l];
              //左右按钮开关//
    UISwitch *ll = [[UISwitch alloc] initWithFrame:CGRectMake(150, 160, 100, 44)];
    ll.tintColor = [UIColor redColor];//开关颜色
    [self.view addSubview:ll];
    [ll addTarget:self action:@selector(onSwitch:) forControlEvents:UIControlEventValueChanged];
    
    UISlider *lll = [[UISlider alloc] initWithFrame:CGRectMake(30, 600, 100, 40)];
    [self.view addSubview:lll];
    
    //居中
    UISegmentedControl * seg = [[UISegmentedControl alloc]initWithItems:@[@"左对齐",@"居中",@"右对齐"]];
    [seg sizeToFit];
    seg.center = CGPointMake(190, 300);
    [seg addTarget:self action:@selector(onSeg:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:seg];
    
}
//左右居中的方法
- (void)onSeg:(UISegmentedControl *)seg
{
    UILabel *l = (UILabel *)[self.view viewWithTag:100];
    [UIView animateWithDuration:0.6 delay:0 usingSpringWithDamping:0.3 initialSpringVelocity:0.2 options:UIViewAnimationOptionCurveEaseOut animations:^{
        
        if (seg.selectedSegmentIndex == 0) {
            l.center = CGPointMake(16 + l.frame.size.width/2, l.center.y);
        }else if(seg.selectedSegmentIndex == 1){
            l.center = CGPointMake(self.view.frame.size.width/2, l.center.y);
        }else{
            l.center = CGPointMake(self.view.frame.size.width - (16 + l.frame.size.width/2), l.center.y);
        }
    } completion:nil];
}
//设计开关的功能  开关的边框
-(void)onSwitch:(UISwitch *)ll
{
    UILabel *l =[(UILabel *)self.view viewWithTag:100];
    if(ll.isOn)
    {
        l.layer.borderWidth = 1;
    }else
    {
        l.layer.borderWidth = 0;
    }
}
//按钮的颜色
-(void)onCick:(UIButton *)sender
{
    sender.backgroundColor = [UIColor whiteColor];
    
}

-(void)onCick2:(UIButton *)sender
{
    sender.backgroundColor = [UIColor greenColor];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
